<style lang="less">
  .searchb{
    width: 90vw;
    margin-left: 5vw;
  }
  .search{
    width: 29vw;
  }
  .search_date{
    width: 44vw;
  }
  .ShouItemData{
    font-size: 2vw;
    font-weight: 800;
  }
  .xiatable{
     .cell{
        line-height: 2vw !important;
     }
  }


  table {border-collapse:collapse;}
  table tr td{border:1px solid #d4dedd;}
</style>

<template>
  <div >
    <el-collapse v-model="activeNames">
      <el-collapse-item  name="1">
        <template slot="title">
          <p style="margin-left: 3vw;font-size: 1vw;font-weight: 800;">上料执行台</p>
        </template>
        <el-form class="searchb"  label-width="80px" ref="form" size="small"  :model="formfa"  :inline="true">
          <el-form-item label="车间" >
              <el-input v-model="formfa.workshop"></el-input>
          </el-form-item>
         <el-form-item label="类别">
            <el-select v-model="formfa.category" filterable placeholder="请选择">
              <el-option  v-for="(item,i) in category_options" :key="i" :label="item" :value="i">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="节号" >
              <el-input v-model="formfa.batch_name"></el-input>
          </el-form-item>
          <el-form-item label="下单时间">
            <el-date-picker style="width: 22vw;" v-model="formfa.productive_time" type="datetimerange" range-separator="至" start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="备料">
            <el-select v-model="formfa.stock" filterable placeholder="请选择">
              <el-option  v-for="(item,i) in stock_options" :key="i" :label="item" :value="i">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
               <el-button type="primary" @click="getplmlistfa">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          v-loading="loadingfa"
          size="mini"
          :data="tableDatafa"
          :span-method="objectSpanMethodfa"
          :cell-style = "cellStyleShou"
          :header-cell-style = "headerCellStyle"
          @sort-change = "sortFa"
          ref="formtablefa"
          max-height = "600"
          border
          style="margin-left:1vw;">

         <el-table-column
           type="selection"
           width="40">
          </el-table-column>
          <el-table-column
            prop="status_name"
            label="状态"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="stock_name"
            label="备料"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="color"
            label="颜色"
            >
          </el-table-column>
          <el-table-column
            prop="color_code"
            label="色号"
            width="60"
            >
          </el-table-column>
          <el-table-column
            label="节号"
            width="100">
           <template slot-scope="data">
               <div v-for="b in data.row.batch_names">{{b}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="go_on"
            label="接龙"
            width="70"
            >
          </el-table-column>
          <el-table-column
            prop="yhh_id"
            label="优化号"
            width="70"
            >
          </el-table-column>
          <el-table-column
            prop="mc_names"
            label="类别"
            width="70"
            >
          </el-table-column>

          <el-table-column
            prop="amount"
            label="数量"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="count"
            label="总数"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="heap_number"
            label="堆号"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="machine_number"
            label="机台号"
            width="60"
            >
          </el-table-column>

          <el-table-column
            prop="remark"
            label="备注"
            >
          </el-table-column>
          <el-table-column
            prop="workshop"
            label="车间"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="guige"
            label="规格"
            width="60"
            >
          </el-table-column>
          <el-table-column
            prop="square"
            label="平方"
            width="100"
            >
          </el-table-column>
          <el-table-column
            prop="thickness"
            label="厚度"
            width="60"
            >
          </el-table-column>
          <el-table-column prop="creator_name" width="70" label="创建人">
          </el-table-column>
          <el-table-column sortable="custom" prop="productive_time" label="实际计划下单时间">
          </el-table-column>
        </el-table>
        <el-pagination
          style="text-align: right;"
          @current-change="handleCurrentChangeFa"
          @size-change="handleSizeChangeFa"
          :current-page="pagintionFa.page"
          :page-size="pagintionFa.page_size"
          :page-sizes="pagesizes"
          layout="total, prev, pager, next, jumper,sizes"
          :total="pagintionFa.total">
        </el-pagination>
        <el-form class="searchb" size="small"  label-width="80px" :model="form_on"  :inline="true">
          <el-form-item v-show="production_dispatch_accomplish">
              <el-button type="primary" @click="execute_on">执行任务</el-button>
          </el-form-item>
          <el-form-item v-show="production_dispatch_execute">
              <el-button type="primary" @click="stock_accomplish">备料</el-button>
          </el-form-item>
          <el-form-item v-show="production_dispatch_execute">
              <el-button type="primary" @click="cancel_stock_accomplish">取消备料</el-button>
          </el-form-item>
          <el-form-item label="电梯口" v-show="production_dispatch_accomplish">
              <el-select v-model="form_on.elevator_number" placeholder="请选择">
                  <el-option
                    v-for="item in elevator_number_options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
              </el-select>
          </el-form-item>
          <el-form-item v-show="production_dispatch_accomplish">
              <el-checkbox v-model="form_on.urgent">加急</el-checkbox>
          </el-form-item>
          
          <el-form-item style="margin-left:50px;">
              <el-button type="primary" @click="query_data">查询全部数据</el-button>
          </el-form-item>
        </el-form>
        <div style="height:5px;background: gray;"></div>
      </el-collapse-item>
      <el-collapse-item title="上料进度台" name="2">
        <template slot="title">
          <p style="margin-left: 3vw; font-size: 1vw;font-weight: 800;">上料进度台</p>
        </template>
        <el-table
          class="xiatable"
          v-loading="loadingshou"
          :data="tableDatashou"
          :span-method="objectSpanMethodshou"
          :cell-style = "cellStyleShou"
          :header-cell-style = "headerCellStyle"
          @sort-change = "sortchange"
          ref="formtableshou"
          max-height = "600"
          border
          style="margin-left:1vw;">

         <el-table-column
           type="selection"
           width="40">
          </el-table-column>
         <el-table-column
            prop="status_name"
            label="状态"
            sortable="custom"
            width="200"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.status_name}}</div>
            </template>
          </el-table-column>

          <!-- <el-table-column
            prop="color"
            label="颜色"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.color}}</div>
            </template>
          </el-table-column> -->
          <el-table-column
            prop="heap_number"
            label="堆号"
            width="160"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.heap_number}}</div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="machine_number"
            label="机台号"
            width="80"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.machine_number}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="workshop"
            label="车间"
            width="100"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.workshop}}</div>
            </template>
          </el-table-column> -->
          <el-table-column
            prop="elevator_number"
            label="电梯口"
            width="160"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.elevator_number}}</div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="amount"
            label="数量"
            width="80"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.amount}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="count"
            label="总数"
            width="80"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.count}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="thickness"
            label="厚度"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.thickness}}</div>
            </template>
          </el-table-column> -->
          <el-table-column
            prop="productive_time"
            label="实际计划下单时间"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.productive_time}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="expect_accomplish_time"
            label="剩余时间"
            >
            <template slot-scope="data">
               <div class="ShouItemData">{{data.row.expect_accomplish_time}}</div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="节号"
            width="220"
            >
            <template slot-scope="data">
               <div class="ShouItemData" v-for="b in data.row.batch_names">{{b}}</div>
            </template>
          </el-table-column> -->
        </el-table>
        <el-pagination
          style="text-align: right;"
          @size-change="handleSizeChangeShou"
          @current-change="handleCurrentChangeShou"
          :current-page="pagintionShou.page"
          :page-size="pagintionShou.page_size"
          :page-sizes="pagesizes"
          layout="total, prev, pager, next, jumper,sizes"
          :total="pagintionShou.total">
        </el-pagination>
        <el-form class="searchb" size="small"  label-width="80px"   :inline="true">
          <el-form-item v-show="production_dispatch_accomplish" >
              <el-button type="primary" @click="affirm_accomplish">确认收料</el-button>
          </el-form-item>
          <el-form-item  v-show="production_dispatch_execute">
              <el-button type="primary" @click="execute_accomplish" >确认送料</el-button>
          </el-form-item>
          <el-form-item  v-show="production_dispatch_accomplish">
              <el-button type="primary" @click="cancel_request" >退回请求</el-button>
          </el-form-item>
          <el-form-item  v-show="production_dispatch_execute">
              <el-button type="primary" @click="cancel_delivery" >取消送料</el-button>
          </el-form-item>
          <el-form-item  v-show="production_dispatch_accomplish">
              <el-button type="primary" @click="edit_urgent" >加急</el-button>
          </el-form-item>
          <el-form-item label="电梯口" v-show="production_dispatch_accomplish">
              <el-select v-model="elevator_number_shou" placeholder="请选择">
                  <el-option
                    v-for="item in elevator_number_options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
              </el-select>
          </el-form-item>
          <el-form-item  v-show="production_dispatch_accomplish">
              <el-button type="primary" @click="edit_elevator" >修改电梯口</el-button>
          </el-form-item>
          <el-form-item v-show="production_dispatch_accomplish" style="margin-left:50px;">
              <el-button type="primary" @click="alfter_machine_number">修改机台号</el-button>
          </el-form-item>
          <el-form-item label="机台号" v-show="production_dispatch_accomplish">
              <el-input v-model="machine_number"></el-input>
          </el-form-item>
        </el-form>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
  import 'boqii-modal'
  import Axios from 'axios';
  import Vue from 'vue';
  import { getList,execute_on,execute_accomplish,affirm_accomplish,edit_elevator,edit_urgent,getMaterialCategory,post_machine_number,getProductionPermission} from '@/request/api';

	export default {
	  data () {
	    return {
        activeNames: ['1','2'],
        pagesizes:[3,10,20,40,100,200],
        pagintionFa:{
          total:0,
          page_size:5,
          page:1
        },
        pagintionShou:{
          total:0,
          page_size:5,
          page:1
        },
        sortShou:{status_name:"",ctime:"",request_time:""},
        sortShou:{ctime:""},
        loadingfa : false,
        loadingshou : false,
        fileList: [],
        elevator_number_shou:'',
        elevator_number_options:[{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }],
        formfa:{
          batch_name:'',
          yhh_id:'',
          workshop:'',
          category:'',
          productive_time : ['', ''],
          stock:''
        },
        form_on:{
          elevator_number:'',
          urgent:false
        },
        objectSpandatafa:{},
        objectSpandatashou:{},
        columnIndexsFa:[0,1,2,10,11,12,18,19],
        columnIndexsShou:[0,1,3,4,5,7,10,11,],
        tableDatafa: [],
        tableDatashou: [],
        timerc:'',
        duration:0,
        production_dispatch_execute:false,
        production_dispatch_accomplish:false,
        category_options:[],
        stock_options:{'':'','0':'未备料','1':'已备料'},
        //机台号
        machine_number:'',
	    }
	  },
    mounted(){
      this.getProductionPermission();
      this.timer();
      this.getmaterial_category();
    },
    methods:{
      sortFa(val){
        if(val.order == 'ascending'){
          val.order = 'asc';
        }else if(val.order == 'descending'){
          val.order = 'desc';
        }else{
          val.order = '';
        }
        this.sortFa[val.prop] = val.order;
        this.getplmlistfa();
      },
      sortchange(val){
        this.sortShou.status_name = '';
        this.sortShou.ctime = '';
        this.sortShou.request_time='';
        if(val.order == 'ascending'){
          val.order = 'asc';
        }else if(val.order == 'descending'){
          val.order = 'desc';
        }else{
          val.order = '';
        }
        this.sortShou[val.prop] = val.order;
        this.getplmlistshou();
      },
      handleSizeChangeFa(val) {
        this.pagintionFa.page_size = val;
        this.getplmlistfa();
      },
      handleSizeChangeShou(val) {
        this.pagintionShou.page_size = val;
        this.getplmlistshou();
      },
      //获取物料类别
      getmaterial_category(){
        getMaterialCategory().then(res => {
          for(var i = 0 ; i < res.length-1 ; i++){

          }
          this.category_options = res;
        })
      },
      //修改上表页数
      handleCurrentChangeFa(val){
        this.pagintionFa.page = val;
        this.getplmlistfa();
      },
      //修改下表页数
      handleCurrentChangeShou(val){
        this.pagintionShou.page = val;
        this.getplmlistshou();
      },
      //退回请求
      cancel_request(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status != 3){
            this.$confirm('任务'+data.id+'不是请求送料，不能退回请求')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }
        param.plmd_ids = plmd_ids;
        param.status = 'cancel_request';
        execute_on(param).then(res => {
          this.pagintionShou.page = 0;
          this.getplmlistshou();
        })
      },
      alfter_machine_number(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          plmd_ids[i] = datas[i].id;
        }
        param.plmd_ids = plmd_ids;
        param.machine_number = this.machine_number;
        post_machine_number(param).then(res => {
          this.pagintionFa.page = 1;
          this.pagintionShou.page = 1;
          this.getplmlistfa();
          this.getplmlistshou();
        })
      },
      //取消送料
      cancel_delivery(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status != 4){
            this.$confirm('任务'+data.id+'不是送料中，不能取消送料')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }
        param.plmd_ids = plmd_ids;
        param.status = 'cancel_delivery';
        execute_accomplish(param).then(res => {
          this.pagintionShou.page = 1;
          this.getplmlists();
        })
      },
      //请求执行
      execute_on(){
        var datas = this.$refs.formtablefa.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          if(datas[i].stock != 1){
            this.$confirm('任务'+datas[i].id+'未备料，不能请求执行')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = datas[i].id;
        }
        param.plmd_ids = plmd_ids;
        param.elevator_number = this.form_on.elevator_number;
        if(this.form_on.elevator_number == ""){
          this.$confirm('电梯口不能为空')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        if(this.form_on.urgent){
          param.urgent = 1;
        }else{
          param.urgent = 0;
        }
        param.status = 'execute_on';
        execute_on(param).then(res => {
          this.pagintionFa.page = 1;
          this.pagintionShou.page = 1;
          this.getplmlistfa();
          this.getplmlistshou();
        })
      },
      //备料
      stock_accomplish(){
        var datas = this.$refs.formtablefa.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          plmd_ids[i] = datas[i].id;
        }
        param.plmd_ids = plmd_ids;
        param.status = 'stock_accomplish';
        execute_accomplish(param).then(res => {
          this.pagintionFa.page = 1;
          this.pagintionShou.page = 1;
          this.getplmlistfa();
          this.getplmlistshou();
        })
      },
      //备料
      cancel_stock_accomplish(){
        var datas = this.$refs.formtablefa.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          plmd_ids[i] = datas[i].id;
        }
        param.plmd_ids = plmd_ids;
        param.status = 'cancel_stock_accomplish';
        execute_accomplish(param).then(res => {
          this.pagintionFa.page = 1;
          this.pagintionShou.page = 1;
          this.getplmlistfa();
          this.getplmlistshou();
        })
      },
      //收料
      affirm_accomplish(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status != 4){
            this.$confirm('任务'+data.id+'没有提交完成，不能确认完成')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }
        param.plmd_ids = plmd_ids;
        affirm_accomplish(param).then(res => {
          this.pagintionShou.page = 1;
          this.getplmlistshou();
        })
      },
      //确认已经送料
      execute_accomplish(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        console.log(datas);
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status != 3){
            this.$confirm('任务'+data.id+'不是请求送料，不能送料')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }
        param.plmd_ids = plmd_ids;
        param.status = 'execute_accomplish';
        execute_accomplish(param).then(res => {
          this.pagintionShou.page = 0;
          this.getplmlistshou();
        })
      },
      //修改电梯口
      edit_elevator(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status == 4){
            this.$confirm('任务'+data.id+'已经提交完成，不能修改电梯口')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }

        if(this.elevator_number_shou == ""){
          this.$confirm('电梯口不能为空')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        param.plmd_ids = plmd_ids;
        param.elevator_number = this.elevator_number_shou;
        edit_elevator(param).then(res => {
          this.pagintionShou.page = 0;
          this.getplmlistshou();
        })
      },
      //修改加急状态
      edit_urgent(){
        var datas = this.$refs.formtableshou.selection;
        var param = {};
        var plmd_ids = [];
        if(datas.length === 0){
          this.$confirm('必须勾选任务')
              .then(_ => {
                done();
              })
              .catch(_ => {});
          return;
        }
        for(var i = 0 ;i < datas.length ;i++){
          var data = datas[i];
          if(data.status == 4){
            this.$confirm('任务'+data.id+'已经提交完成，不能修改加急状态')
                .then(_ => {
                  done();
                })
                .catch(_ => {});
            return;
          }
          plmd_ids[i] = data.id;
        }
        param.plmd_ids = plmd_ids;
        param.urgent = 1;
        edit_urgent(param).then(res => {
          this.pagintionShou.page = 1;
          this.getplmlistshou();
        })
      },
      //加急设置背景颜色
      cellStyleShou(row, column, rowIndex, columnIndex){
        var style = {};
        style.color = 'black';
        if(row.row.urgent_name==="加急"){
          style.background = '#f7db6f';
        }
        if(row.row.status === "4"){
          style.background = '#b1eeb4';
        }
        return style;
      },
      //设置表头style
      headerCellStyle(row, rowIndex){
        return {background:'#eee',color:'#606266','text-align': 'center'};
      },
      //为上表单元格合并
      objectSpanMethodfa({row, column, rowIndex, columnIndex}) {
        if(this.columnIndexsFa.indexOf(columnIndex) > -1){
          for(var key in this.objectSpandatafa){
                 if(rowIndex == key){
                   if(this.objectSpandatafa[key] > 1){

                      return {
                         rowspan: this.objectSpandatafa[key],
                         colspan: 1
                      };
                   }else{
                     return;
                   }

                 }
          }
        }
        if(this.columnIndexsFa.indexOf(columnIndex) > -1){
          return {
             rowspan: 0,
             colspan: 0
          };
         }
      },
      //下表单元格合并
      objectSpanMethodshou({ row, column, rowIndex, columnIndex }) {
        // if(this.columnIndexsShou.indexOf(columnIndex) > -1){
        //   for(var key in this.objectSpandatashou){
        //          if(rowIndex == key){
        //            if(this.objectSpandatashou[key] > 1){

        //               return {
        //                  rowspan: this.objectSpandatashou[key],
        //                  colspan: 1
        //               };
        //            }else{
        //              return;
        //            }

        //          }
        //   }
        // }
        // if(this.columnIndexsShou.indexOf(columnIndex) > -1){
        //   return {
        //      rowspan: 0,
        //      colspan: 0
        //   };
        //  }
      },
      getProductionPermission(){
        getProductionPermission().then(res => {
          this.production_dispatch_accomplish = res.msg.production_dispatch_accomplish;
          this.production_dispatch_execute = res.msg.production_dispatch_execute;
          this.getplmlistfa();
          this.getplmlistshou();
        })
      },
      //上表数据获取
      getplmlistfa(){
        this.duration = 0;
        this.loadingfa = true;
        var param = {};
        param.page = this.pagintionFa.page-1;
        param.pagesize = this.pagintionFa.page_size;
        if(this.sortFa.ctime != ''){
          param['searchParams[ctime_sort]'] = this.sortFa.ctime;
        }
        param['searchParams[batch_name]'] = this.formfa.batch_name;
        param['searchParams[category]'] = this.formfa.category;
        param['searchParams[workshop]'] = this.formfa.workshop;
        param['searchParams[status]'] = 2;
        if(this.formfa.stock != ""){
          param['searchParams[stock]'] = this.formfa.stock;
        }
        
        // param['searchParams[productive_time_start]'] = this.formfa.productive_time[0];
        // param['searchParams[productive_time_end]'] = this.formfa.productive_time[1];
        param['searchParams[time_filter][time_category]'] = 'batch.productive_time';
        if(this.formfa.productive_time[0] != null){
          param['searchParams[time_filter][start_time]'] = this.formfa.productive_time[0];
        }
        if(this.formfa.productive_time[1] != null){
          param['searchParams[time_filter][end_time]'] = this.formfa.productive_time[1];
        }
        getList(param).then(res => {
          this.loadingfa = false;
          this.setdata(res.msg.instruct,'fa');
          this.pagintionFa.total = parseInt(res.msg.total);
        },err => {
          // console.log(err);
          this.loadingfa = false;
        })
       },
      //下表数据获取
      getplmlistshou(){
        this.duration = 0;
        this.loadingshou = true;
        var param = {};
        param.page = this.pagintionShou.page-1;
        param.pagesize = this.pagintionShou.page_size;

        if(this.sortShou.status_name != ''){
          param['searchParams[status_sort]'] = this.sortShou.status_name;
        }
        if(this.sortShou.ctime != ''){
          param['searchParams[ctime_sort]'] = this.sortShou.ctime;
        }
        if(this.sortShou.request_time != ''){
          param['searchParams[request_time_sort]'] = this.sortShou.request_time;
        }
        param['searchParams[expect_accomplish_time_sort]'] = 'asc';
        if(this.production_dispatch_execute && !this.production_dispatch_accomplish){
          param['searchParams[status][0]'] = '3';
          param.pagesize = 3;
        }else{
          param['searchParams[status][0]'] = '3';
          param['searchParams[status][1]'] = '4';
        }
        getList(param).then(res => {
          this.loadingshou = false;
          this.setdateshou(res.msg.instruct);
          this.pagintionShou.total = parseInt(res.msg.total);
        },err => {
          // console.log(err);
          this.loadingshou = false;
         })
        },
      setdateshou(datas){
        this.objectSpandatashou = {};
        this.tableDatashou.length = 0;
        let id = 0;
        for(var bean of datas){
          if(id != bean.id){
            id = bean.id;
            var databean = {};
            databean.id = bean.id;
            databean.status = bean.status;
            switch(bean.status){
              case "1": databean.status_name = "新任务";
                    break;
              case "2": databean.status_name = "未送料";
                    break;
              case "3": databean.status_name = "请求送料";
                    break;
              case "4": databean.status_name = "送料中";
                    break;
              case "5": databean.status_name = "已收料";
                    break;
            }
            databean.heap_number = bean.heap_number;
            databean.elevator_number = bean.elevator_number;
            databean.productive_time = this.getdate(bean.productive_time);;
            var timestamp = Date.parse(new Date())/1000;
            if(bean.expect_accomplish_time > timestamp){
              if(bean.status == 4){
                databean.expect_accomplish_time = '';
              }else{
                databean.expect_accomplish_time = parseInt((bean.expect_accomplish_time - timestamp)/60)+'分钟';
              }
            }else{
              databean.expect_accomplish_time = 0+'分钟';
            }
            this.tableDatashou.push(databean);
          }
        }
      },
      //解析网络访问获得的数据
      //解析表数据
      //表数据解析
      setdata(data,code){
         var row = 0;
         var index = 0;
         if(code == "fa"){
           this.objectSpandatafa = {};
           this.tableDatafa.length = 0;
         }else if(code == "shou"){
           this.objectSpandatashou = {};
           this.tableDatashou.length = 0;
         }

         for(var i = 0;i < data.length;i++){
           var bean = data[i];
            if(i != 0){
              var obean = data[i-1];
              if(obean.id == bean.id){
                row++;
              }else{
                index = i;
              }
            }else{
              index = i;
              row++;
            }
            if(i < data.length-1){
              var nbean = data[i+1];
              if(nbean.id != bean.id){
                if(code == "fa"){
                  this.objectSpandatafa[index] = row;
                }else if(code == "shou"){
                  this.objectSpandatashou[index] = row;
                }
                row=1;
              }
            }else{
              if(code == "fa"){
                this.objectSpandatafa[index] = row;
              }else if(code == "shou"){
                this.objectSpandatashou[index] = row;
              }
              row=1;
            }
            var databean = {};
            databean.id = bean.id;
            databean.status = bean.status;
            switch(bean.status){
              case "1": databean.status_name = "新任务";
                    break;
              case "2": databean.status_name = "未送料";
                    break;
              case "3": databean.status_name = "请求送料";
                    break;
              case "4": databean.status_name = "送料中";
                    break;
              case "5": databean.status_name = "已收料";
                    break;
            }
            if(bean.batch_names != null){
              databean.batch_names = bean.batch_names.split(",");
            }
            databean.machine_number = bean.machine_number;
            databean.color = bean.color;
            databean.color_code = bean.color_code;
            databean.go_on = bean.go_on;
            databean.yhh_id = bean.yhh_id;
            if(bean.isyhh == 1){
              databean.yhh_id = "";
            }
            databean.amount = bean.amount;
            databean.count = bean.sum;
            databean.heap_number = bean.heap_number;
            // databean.remark = bean.remark;
            databean.workshop = bean.workshop;
            databean.square = bean.square;
            databean.remark = bean.yhh_remark;
            databean.thickness = bean.thickness;
            if(bean.urgent == '0'){
              databean.urgent_name = '不加急';
            }else if(bean.urgent == '1'){
              databean.urgent_name = '加急';
            }
            if(bean.stock == '0'){
              databean.stock_name = '未备料';
            }else if(bean.stock == '1'){
              databean.stock_name = '已备料';
            }
            databean.stock = bean.stock;
            databean.guige = bean.guige;
            databean.urgent = bean.urgent;
            databean.elevator_number = bean.elevator_number;
            databean.creator_name = bean.creator_name;
            databean.feed_name = bean.feed_name;
            databean.reap_name = bean.reap_name;
            databean.mc_names = bean.mc_names;
            databean.ctime = this.getdate(bean.ctime);
            databean.accomplish_time = this.getdate(bean.accomplish_time);
            databean.request_time = this.getdate(bean.request_time);
            databean.productive_time = this.getdate(bean.productive_time);
            var timestamp = Date.parse(new Date())/1000;
            if(bean.expect_accomplish_time > timestamp){
              if(bean.status == 4){
                databean.expect_accomplish_time = '';
              }else{
                databean.expect_accomplish_time = parseInt((bean.expect_accomplish_time - timestamp)/60)+'分钟';
              }
            }else{
              databean.expect_accomplish_time = 0+'分钟';
            }
            if(code == "fa"){
              this.tableDatafa.push(databean);
            }else if(code == "shou"){
              this.tableDatashou.push(databean);
            }
         }
      },
      getdate(date){
        if(date == null || date == ""){
          return "";
        }
        // console.log(date);
        date = parseInt(date)*1000;
        var date = new Date(date);
        var YY = date.getFullYear() + '-';
        var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
        var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
        return YY + MM + DD +" "+hh + mm + ss;
      },
      timer(){
        window.clearTimeout(this.timerc);
        this.timerc = setTimeout(() => {
          this.duration = this.duration+1;
          console.log(this.duration);
          if(this.duration > 60){
            this.getplmlistfa();
            this.getplmlistshou();
          }
          this.timer();
        },1000)
      },
      query_data(){
        this.$router.replace({
            path: '/production_load_material',
        });
      }
    },


	}
</script>
